home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / CHSIZE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  867 b   |  35 lines

  1. /* chsize.c, from page 352 of Turbo C Bible */
  2. #include <stdio.h>
  3. #include <fcntl.h>
  4. #include <io.h>
  5. main ()
  6. {
  7.    int filehandle, answer = 0;
  8.    char filename [80];
  9.    printf ("Enter name of file to truncate: ");
  10.    gets (filename);
  11.    if ((filehandle = open (filename, O_RDWR)) == -1)
  12.    {
  13.         perror ("open failed");
  14.         exit (1);
  15.    }
  16.             /* Now give user a warning and a chance to abort */
  17.    while (answer != 'N' && answer != 'Y')
  18.    {
  19.         printf ("Truncate %s to size zero? (Y or N)",
  20.                   filename);
  21.         scanf (" %1s", &answer);
  22.         answer = toupper (answer);
  23.    }
  24.    if (answer == 'Y')
  25.    {
  26.     if (chsize (filehandle, 0L) == -1)
  27.         {
  28.              perror ("chsize failed");
  29.         }
  30.         else
  31.         {
  32.              printf ("%s successfully truncated.\n", filename);
  33.         }
  34.    }
  35. }